package com.kangye.game.controller;

import com.alibaba.fastjson.JSON;
import com.kangye.game.pojo.TUser;
import com.kangye.game.service.LoginService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: game_orders
 * @description: 登录控制器
 * @CrossOrigin--前后端分离必须跨域
 * @author: lys
 * @create: 2021-09-01 11:54
 **/
@RestController
@CrossOrigin
public class LoginController {

    @Resource
    private LoginService loginService;

    @RequestMapping("/getLogin.action")
    public Object getLogin(String loginname, String password) {
        System.out.println(loginname + "---" + password);
        //调用loginService得到TUser的返回值
        List<TUser> tUsers = new ArrayList<>();
        tUsers = loginService.getLogin(loginname, password);
        Map<String, String> map = new HashMap<>();
        if (tUsers != null) {
            //成功后返回200
            String s = JSON.toJSONString("200");
            //将对象改为json格式--并添加到map集合
            String t_user = JSON.toJSONString(tUsers);
            map.put("code", s);
            map.put("TUser", t_user);
        } else {
            //失败后返回400
            String s1 = JSON.toJSONString("400");
            map.put("code", s1);
        }
        return map;
    }
}
